(function($){
	$(function(){
		//注册界面选项卡
		var 
			aLi = $(".regnav ul li"),
			aSpan = $(".icon4"),
			bSpan = $(".icon3"),
			aReg = $(".phonereg");
		aLi.click(function(){
			var aIndex = $(this).index();
			aLi.removeClass("on").eq(aIndex).addClass("on");
			aReg.css("display","none").eq(aIndex).css("display","block");
		})
		aLi.eq(0).click(function(){
			bSpan.css("background-position-y","-304px");
			aSpan.css("background-position-y","-233px");
		})
		aLi.eq(1).click(function(){
			bSpan.css("background-position-y","-286px");
			aSpan.css("background-position-y","-212px");
		})
		
		//注册页面格式判断
		var 
		oInput=$('.phonereg input').not("#btn1"),
		oPhone=$('#p-num'),
		oFirpsw=$('.text2'),
		oSecpsw=$('.text3'),
		oMa=$('.text8');
		
		oInput.focus(function(){
			var oIndex=oInput.index($(this))
			oInput.removeClass('active').eq(oIndex).addClass('active');
		}).blur(function(){
			oInput.removeClass('active');
		});
		
		//手机号
		oPhone.focus(function(){
			$("#a01").css("display","block");
			
		}).blur(function(){
		
			var 
				reg1=/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
			    
			if(!oPhone.val()){
				$("#etips").css("display","block");
				return false;
			}else if(!reg1.test(oPhone.val())){
				$("#a02").css("display","block");
				return false;
			}else{
				$(".land_ico").css("background-position","0 -275px");
				$("#a01").css("display","none");
				$("#a02").css("display","none");
				$("#etips").css("display","none");
				return false;
			}
		});
			
		//首次输入密码
		oFirpsw.focus(function(){
			$("#text22").css("display","block");
		}).blur(function(){
		
			var 
				reg2= /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;
				
			if(!oFirpsw.val()){
				$("#etips22").css("display","block");
				return false;
			}else if(!reg2.test(oFirpsw.val())){
				$("#psw22").css("display","block");
				return false;
			}else{
				$(".land_ico2").css("background-position","0 -275px");
				$("#text22").css("display","none");
				$("#psw22").css("display","none");
				$("#etips22").css("display","none");
				return false;
			}
		})
		
		//再次判断密码
		oSecpsw.focus(function(){
			$("#b01").css("display","block");
		}).blur(function(){
		
			
			if(!oSecpsw.val()){
				$("#b03").css("display","block");
				return false;
			}else if(oSecpsw.val()!=oFirpsw.val()){
				$("#b02").css("display","block");
				return false;
			}else{
				$(".land_ico3").css("background-position","0 -275px");
				$("#b01").css("display","none");
				$("#b02").css("display","none");
				$("#b03").css("display","none");
				return false;
			}
		})
		
		//验证码
		var 
			switchBtn=$('.cg'),
			randomBox=$('.yanma'),
			str='0123456789abcdefghijklmnopqrstuvwxyz';//四位数字和字母

		switchBtn.click(function(){
			var
				newArr=[];
			for(var i=0 ; i<4; i++){
				newArr.push(str[parseInt(Math.random()*36)]);
			}
			randomBox.html(newArr.join(""))
			
		});
		
			
		oMa.focus(function(){
			$("#putyan").css("display","block");
		}).blur(function(){
			if(oMa.val()!=randomBox.html()){
				$("#wrongyan").css("display","block");
			}
				$("#putyan").css("display","none");
				$("#wrongyan").css("display","none");
			
		});
			
		
			
		
		
		//注册按钮
		$('#btn1').click(function(){
			if(oPhone.val() && oFirpsw.val() && oMa.val()){
				//设置cookie
				setCookies("text1",oPhone.val(),10);
			  	setCookies("text2",oFirpsw.val(),10);
			  	window.location.href='login.html'
			}
				
		})
		
		
		
		//登录页面
		var
			cInput=$('.yhm_text');
			
		cInput.focus(function(){
			var cIndex=$(this).index(".yhm_text");
			
			cInput.removeClass('active').eq(cIndex).addClass('active')
		});
		
		//获取cookie
		var 
			username=getCookie('text1'),
			userpsw=getCookie('text2'),
			phone=$('#yz_user'),
			firpsw=$('#yz_user1');
			
		
		phone.blur(function(){
			if(phone.val()==username){
				$(".land_icn").css("background-position","0 -275px");
				$("#tips11").css("display","none");
			}else if(phone.val()!=username){
				$("#tips11").css("display","block");
			}
		})
		firpsw.blur(function(){
			if(firpsw.val()==userpsw){
				$(".land_icn2").css("background-position","0 -275px");
			}
		})
		//登录按钮
			
		$('.btn-img').click(function(){
			if(phone.val()==username && firpsw.val()==userpsw){
				//window.open('index.html',"_self")
				window.location.href='../index.html'
			}
		})
	});
})(jQuery);
